package com.ubi.core.framework;

import com.ubi.core.framework.job.JobRegistry;
import com.ubi.core.framework.job.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * @author raymond
 */
@EnableScheduling
public abstract class AbstractSchedulerConfig implements SchedulingConfigurer {

    @Autowired
    protected ConfigurableEnvironment environment;

    @Autowired
    Scheduler scheduler;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setTaskScheduler(scheduler.getScheduler());
        JobRegistry jobRegistry = new JobRegistry(taskRegistrar);
        configure(jobRegistry);
    }

    public abstract void configure(JobRegistry jobRegistry);
}
